<template>
  <el-container class="admin-layout">
    <el-aside width="200px">
      <el-menu
        :router="true"
        :default-active="$route.path"
        class="admin-menu"
        background-color="#304156"
        text-color="#bfcbd9"
        active-text-color="#409EFF">
        <el-menu-item index="/admin/dashboard">
          <i class="el-icon-s-home"></i>
          <span slot="title">首页</span>
        </el-menu-item>
        <el-menu-item index="/admin/announcements">
          <i class="el-icon-bell"></i>
          <span slot="title">公告管理</span>
        </el-menu-item>
        <el-menu-item index="/admin/departments">
          <i class="el-icon-office-building"></i>
          <span slot="title">院系管理</span>
        </el-menu-item>
        <el-menu-item index="/admin/classes">
          <i class="el-icon-school"></i>
          <span slot="title">班级管理</span>
        </el-menu-item>
        <el-menu-item index="/admin/courses">
          <i class="el-icon-reading"></i>
          <span slot="title">课程管理</span>
        </el-menu-item>
        <el-menu-item index="/admin/teachers">
          <i class="el-icon-user"></i>
          <span slot="title">教师管理</span>
        </el-menu-item>
        <el-menu-item index="/admin/profile">
          <i class="el-icon-setting"></i>
          <span slot="title">个人设置</span>
        </el-menu-item>
      </el-menu>
    </el-aside>
    <el-container>
      <el-header>
        <div class="header-left">
          <h2>学生作业管理系统 - 管理员</h2>
        </div>
        <div class="header-right">
          <el-dropdown @command="handleCommand">
            <span class="el-dropdown-link">
              管理员<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="profile">个人信息</el-dropdown-item>
              <el-dropdown-item command="logout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </el-header>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  name: 'AdminLayout',
  methods: {
    handleCommand(command) {
      if (command === 'profile') {
        this.$router.push('/admin/profile')
      } else if (command === 'logout') {
        localStorage.removeItem('token')
        this.$router.push('/login')
      }
    }
  }
}
</script>

<style scoped>
.admin-layout {
  height: 100vh;
}

.el-aside {
  background-color: #304156;
  height: 100vh;
}

.admin-menu {
  border-right: none;
}

.el-header {
  background-color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 1px 4px rgba(0,21,41,.08);
}

.header-right {
  cursor: pointer;
}

.el-dropdown-link {
  color: #303133;
}

.el-main {
  background-color: #f0f2f5;
  padding: 20px;
}
</style> 